package homework;
import java.util.Map;
import java.util.HashMap;

/**
 * Map
 * @胡承伦
 */
public class MapMethod {
    Map <Integer,BookMap>map=new HashMap<>();
    public void find(int b) {
        for (Integer k:map.keySet()) {
            if (b==k) {
                System.out.println(map.get(b).toString());
                return;
            }
        }
        System.out.println("你要找的图书不存在");
    }

    public void add( BookMap book1) {
        map.put(book1.getMember(),book1);
    }

    public void delete(int m) {
        for (int i = 0; i < map.size(); i++) {
            if (map.get(m) == map.get(i)) {
               map.remove(i);
            }
        }
    }
    public static void main(String[] args) {
        MapMethod book=new MapMethod();
        BookMap a= new BookMap(1, "堂吉诃德", 39.5, "文学出版社");
        BookMap b= new BookMap(2, "草房子", 49.5, "文学出版社");
        BookMap c= new BookMap(3, "善良", 59.5, "文学出版社");
        BookMap d= new BookMap(4, "最美文", 10, "文学出版社");
        //添加图书；
        book.add(a);
        book.add(b);
        book.add(c);
        book.add(d);
        for(Object s:book.map.keySet()){//遍历输出；
            System.out.println(book.map.get(s).toString());
        }
        System.out.println("###########");
        //删除图书；
        //System.out.println(book.map.get(1));
        book.delete(1);
        for(Object s1:book.map.keySet()){//遍历输出；
            System.out.println(book.map.get(s1).toString());
        }
        System.out.println("###########");
        //寻找图书；
        book.find(4);
    }
}
 class BookMap {
    private int member;
    private String name;
    private double price;
    private String publish;

    public BookMap(int member, String name, double price, String publish) {
        this.member = member;
        this.name = name;
        this.price = price;
        this.publish = publish;
    }

    @Override
    public String toString() {
        return "Book{" +
                "member=" + member +
                ", name='" + name + '\'' +
                ", price=" + price +
                ", publish='" + publish + '\'' +
                '}';
    }
    public int getMember() {
        return member;
    }

    public String getName() {
        return name;
    }

    public double getPrice() {
        return price;
    }

    public String getPublish() {
        return publish;
    }
}
